<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\dao\car;


use app\dao\BaseDao;
use app\model\car\CarInfo;

/**
 * Class CarInfoDao
 * @package app\dao\shendeng
 */
class CarInfoDao extends BaseDao
{
    protected function setModel(): string
    {
        return CarInfo::class;
    }
    /**
     * 列表
     * @param array $where
     * @param string $field
     * @param int $page
     * @param int $limit
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList(array $where = [], string $field = '*', int $page = 0,int $limit){
        $model = $this->getModel()->alias('i')->where('i.is_del',0);
        $model = $model->join('car_type t','i.type_id=t.id','left')->join('base_place p','t.place_id=p.id','left')->join('car_type_info ti','t.type_info_id=ti.id','left');
        $model = $model->field('i.*,ti.type_name,p.title,t.place_id,p.name')->order('i.up_time desc');
        if(isset($where['type_info_id']) && $where['type_info_id']){
            $model->where('ti.id','=',$where['type_info_id']);
        }
        if(isset($where['place_id']) && $where['place_id']){
            $model->where('p.id','=',$where['place_id']);
        }
        if(isset($where['status']) && $where['status'] || $where['status'] == '0'){
            $model->where('i.status','=',$where['status']);
        }
        if(isset($where['car_status']) && $where['car_status'] || $where['car_status'] == '0'){
            $model->where('i.car_status','=',$where['car_status']);
        }
        if(isset($where['sxj_status']) && $where['sxj_status'] || $where['sxj_status'] == '0'){
            $model->where('i.sxj_status','=',$where['sxj_status']);
        }
        $count = $model->count();
        $list = $model->page($page,$limit)->select()->toArray();
        return compact('count','list');
    }
}
